package com.hardson.toolkit.swing.datepicker;

import java.awt.Graphics;
import java.awt.Image;

import javax.swing.JLabel;
import javax.swing.JPanel;

public class ImagePanel extends JPanel{

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	protected Image bgImage=null;
	private JPanel pnlLeft=null;
	private JPanel pnlRight=null;
	private String title=null;
	private JLabel lblTitle=null;
	public ImagePanel(){
		this(null);
	}
	public ImagePanel(final Image bgImage){
		this.bgImage=bgImage;
	}
	@Override
	protected void paintComponent(final Graphics g){
		super.paintComponent(g);
		if(this.bgImage!=null){
			this.setOpaque(true);
			int width=this.getWidth();
			int height=this.getHeight();
			int imgWidth=this.bgImage.getWidth(null);
			int imgHeight=this.bgImage.getHeight(null);
			int timesH=1;
			int timesV=1;
			if(width>imgWidth){
				timesH=width/imgWidth;
				if(width%imgWidth>0){
					timesH++;
				}
			}
			if(height>imgHeight){
				timesV=height/imgHeight;
				if(height%imgHeight>0){
					timesV++;
				}
			}
			int posX=0;
			int posY=0;
			for(int j=0;j<timesV;j++,posY=posY+imgHeight){
				for(int i=0;i<timesH;i++,posX=posX+imgWidth){
					g.drawImage(this.bgImage,posX,posY,imgWidth,imgHeight,null);
				}
				posX=0;
			}
		}
	}
}
